{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Quantum Facts in Qiskit\n",
    "Here some useful topics will be covered and others recalled to make you more familiar with quantum terms and concepts.\n",
    "\n",
    "Start by some typical setup and definition of useful functions, which you are encouraged to look at.\n",
    "\n",
    "Then, head to the [exercises start](#Exercises-Start-Here) to start coding!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister\n",
    "from qiskit import execute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Choose the drawer you like best:\n",
    "from qiskit.tools.visualization import matplotlib_circuit_drawer as draw\n",
    "#from qiskit.tools.visualization import circuit_drawer as draw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import IBMQ\n",
    "IBMQ.load_accounts() # make sure you have setup your token locally to use this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utils for visualizing experimental results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def show_results(D):\n",
    "    # D is a dictionary with classical bits as keys and count as value\n",
    "    # example: D = {'000': 497, '001': 527}\n",
    "    plt.bar(range(len(D)), list(D.values()), align='center')\n",
    "    plt.xticks(range(len(D)), list(D.keys()))\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Utils for executing circuits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Aer backends:  [<QasmSimulator('qasm_simulator') from Aer()>, <QasmSimulatorPy('qasm_simulator_py') from Aer()>, <StatevectorSimulator('statevector_simulator') from Aer()>, <StatevectorSimulatorPy('statevector_simulator_py') from Aer()>, <UnitarySimulator('unitary_simulator') from Aer()>, <CliffordSimulator('clifford_simulator') from Aer()>]\n"
     ]
    }
   ],
   "source": [
    "from qiskit import Aer\n",
    "# See a list of available local simulators\n",
    "print(\"Aer backends: \", Aer.backends())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IBMQ Backends:  [<IBMQBackend('ibmqx4') from IBMQ()>, <IBMQBackend('ibmqx5') from IBMQ()>, <IBMQBackend('ibmqx2') from IBMQ()>, <IBMQBackend('ibmq_16_melbourne') from IBMQ()>, <IBMQBackend('ibmq_qasm_simulator') from IBMQ()>]\n"
     ]
    }
   ],
   "source": [
    "# see a list of available remote backends (these are freely given by IBM)\n",
    "print(\"IBMQ Backends: \", IBMQ.backends())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Execute locally"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# execute circuit and either display a histogram of the results\n",
    "def execute_locally(qc, draw_circuit=False):\n",
    "    # Compile and run the Quantum circuit on a simulator backend\n",
    "    backend_sim = Aer.get_backend('qasm_simulator')\n",
    "    job_sim = execute(qc, backend_sim)\n",
    "    result_sim = job_sim.result()\n",
    "    result_counts = result_sim.get_counts(qc)\n",
    "    \n",
    "    # Print the results\n",
    "    print(\"simulation: \", result_sim, result_counts)\n",
    "    \n",
    "    if draw_circuit: # draw the circuit\n",
    "        draw(qc)\n",
    "    else: # or show the results\n",
    "        show_results(result_counts)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Execute remotely"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit.backends.ibmq import least_busy\n",
    "import time\n",
    "# Compile and run on a real device backend\n",
    "def execute_remotely(qc, draw_circuit=False):\n",
    "    if draw_circuit: # draw the circuit\n",
    "        draw(qc)\n",
    "    try:\n",
    "        # select least busy available device and execute.\n",
    "        least_busy_device = least_busy(IBMQ.backends(simulator=False))\n",
    "        print(\"Running on current least busy device: \", least_busy_device)\n",
    "\n",
    "        # running the job\n",
    "        job_exp = execute(qc, backend=least_busy_device, shots=1024, max_credits=10)\n",
    "\n",
    "        lapse, interval = 0, 10\n",
    "        while job_exp.status().name != 'DONE':\n",
    "            print('Status @ {} seconds'.format(interval * lapse))\n",
    "            print(job_exp.status())\n",
    "            time.sleep(interval)\n",
    "            lapse += 1\n",
    "        print(job_exp.status())\n",
    "        exp_result = job_exp.result()\n",
    "        result_counts = exp_result.get_counts(qc)\n",
    "\n",
    "        # Show the results\n",
    "        print(\"experiment: \", exp_result, result_counts)\n",
    "        if not draw_circuit: # show the results\n",
    "            show_results(result_counts)\n",
    "    except:\n",
    "        print(\"All devices are currently unavailable.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Building the circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def new_circuit(size):\n",
    "    # Create a Quantum Register with size qubits\n",
    "    qr = QuantumRegister(size)\n",
    "\n",
    "    # Create a Classical Register with size bits\n",
    "    cr = ClassicalRegister(size)\n",
    "\n",
    "    # Create a Quantum Circuit acting on the qr and cr register\n",
    "    return qr, cr, QuantumCircuit(qr, cr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "<h1 align=\"center\">Exercises Start Here</h1>\n",
    "\n",
    "Make sure you ran all the above cells in order, as the following exercises use functions defined and imported above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Creating Entanglement\n",
    "Although, you have already entangled qubits on the previous week, you were not aware of it.\n",
    "\n",
    "Naturally, we will redo some of those tasks and focus on interpreting their results."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Hadamard + CNOT\n",
    "\n",
    "**TASK:** Create a new circuit with 2 qubits using `new_circuit` (very useful to reconstruct your circuit in Jupyter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a Hadamard on qubit 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# H gate on qubit 0\n",
    "circuit.h(qr[0]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a CX (CNOT) gate on control qubit 0 and target qubit 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "circuit.cx(qr[0], qr[1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Perform a measurement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# measure the qubits\n",
    "circuit.measure(qr, cr);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** check the result using `execute_locally` test both `True` and `False` for the `draw_circuit` option"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'00': 504, '11': 520}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVMAAADYCAYAAABWSwDbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwO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5G0dP8yspKeHl5wcnJqdVrGo0G/v7+yMnJMS8rKCiAyWQyn7L7+fnZpC9LahMpxctTxSDthBQ9Mo2IiEBhYSEyMjIwdepUmEwmGI1G6HQ6AEBcXBySk5Mxfvx4eHt7Q6/XQ6fTITAw0Oa9KVkb4Gk+UWdh8VmiUFhqaqoYNGiQcHd3F76+vmLNmjXm1xoaGsTKlSuFt7e38PDwEDNnzhQVFRUt1t+3b5/48MMP262xceNG8cILL1jVlyW1iYgecPhvjUpNTUVZWVm7N6CIiGzNocN08eLFMBqNqKurw/PPP4+MjAylWyKip5RDhykRUWeh+KR9IqKugGFKRCQBw5SISAKGKRGRBAxTIiIJGKZERBIwTImIJGCYEhFJwDAlIpKAYUpEJAHDlIhIAoYpEZEEDFMiIgkYpkREEjBMiYgkYJgSEUnAMCUikoBhSkQkAcOUiEgChikRkQQMUyIiCRimREQSMEyJiCRgmBIRScAwJSKSgGFKRCQBw5SISIL/B85AA0CCfCXNAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2276a25a748>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Try both commands:\n",
    "execute_locally(circuit,draw_circuit=True)\n",
    "# execute_locally(circuit,draw_circuit=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The result should be something like `COMPLETED {'00': 506, '11': 518}`.\n",
    "\n",
    "**TASK:** What does this mean?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Given two qubits, we could end up with the measurements `00`, `01`, `10` and `11` (4 possibilities)\n",
    "> \n",
    "> However, we got only `00` and `11` (2 cases)! This is due to the fact that our qubits are **entangled**!\n",
    ">\n",
    "> The state of qubit 1 is correlated to that of qubit 0 (control bit). Correlation means the implication is true in both directions.\n",
    ">\n",
    "> By making them entangled, we have ensured that `00` and `11` are the only possible states: if qubit 0 measures to 1 the other qubit, according to our circuit, could never have been 0, as it will be flipped from a starting state of 0.\n",
    ">\n",
    "> Furthermore, we could apply the gates, take both qubits elsewhere (apart from each other) without destroying any superposition, perform the measurements and the result would not change... curious, right?\n",
    ">\n",
    "> This particular disposition of entangled qubits describes what is known as a [Bell state](https://en.wikipedia.org/wiki/Bell_state). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bell state in IBMQ\n",
    "**TASK:** Get the QASM specification for your code and use it on [IBMQ QASM editor](https://quantumexperience.ng.bluemix.net/qx/qasm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OPENQASM 2.0;\n",
      "include \"qelib1.inc\";\n",
      "qreg q0[2];\n",
      "creg c0[2];\n",
      "h q0[0];\n",
      "cx q0[0],q0[1];\n",
      "measure q0[0] -> c0[0];\n",
      "measure q0[1] -> c0[1];\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(circuit.qasm())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> You will probably get an error for trying to execute this QASM, like:\n",
    ">\n",
    "> `Error in line 6: CX gate between q2[0], q2[1] is not allowed in this topology`\n",
    ">\n",
    "> To sort it, simply apply the Hadamard to `q2[1]` and change the CNOT to `cx q2[1] q2[0]`:\n",
    "```qasm\n",
    "OPENQASM 2.0;\n",
    "include \"qelib1.inc\";\n",
    "qreg q2[2];\n",
    "creg c2[2];\n",
    "h q2[1];\n",
    "cx q2[1],q2[0];\n",
    "measure q2[0] -> c2[0];\n",
    "measure q2[1] -> c2[1];\n",
    "```\n",
    "> This is exactly the same circuit, but the norm seems to prefer this orientation rather than our original one (With the control qubit on the CNOT underneath the target qubit)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "### More entanglement\n",
    "**TASK:** Repeat the previous circuit, but add a bit-flip on the target qubit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create the circuit\n",
    "qr, cr, circuit = new_circuit(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a Hadamard on qubit 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# H gate on qubit 0\n",
    "circuit.h(qr[0]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add an X gate on qubit 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# X gate on qubit 1\n",
    "circuit.x(qr[1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a CX (CNOT) gate on control qubit 0 and target qubit 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "circuit.cx(qr[0], qr[1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Perform a measurement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "# measure the qubits\n",
    "circuit.measure(qr, cr);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** check the result using `execute_locally` test both `True` and `False` for the `draw_circuit` option"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'01': 513, '10': 511}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVMAAADYCAYAAABWSwDbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAA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FJwDAlIpKAYUpEJAHDlIhIAoYpEZEEDFMiIgkYpkREEjBMiYgkYJgSEUnAMCUikoBhSkQkAcOUiEgChikRkQQMUyIiCRimREQSMEyJiCRgmBIRScAwJSKSgGFKRCQBw5SISIL/D/uUEwjC+2QTAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2276c2fb780>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Try both commands:\n",
    "execute_locally(circuit,draw_circuit=True)\n",
    "# execute_locally(circuit,draw_circuit=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Observe the results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> The same phenomena happened, however the states now were `01` and `10`, only 2 out of 4 possibilities!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Quantum measurement in different basis\n",
    "Given any of our previous circuits, we are going to measure them on both the zero-one basis as well as on the plus-minus basis."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Reconstruct one of the previous circuits (do not apply the measurement yet)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create the circuit\n",
    "qr, cr, circuit = new_circuit(2)\n",
    "circuit.h(qr[0])\n",
    "circuit.cx(qr[0], qr[1]);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Add a Hadamard after each qubit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "circuit.h(qr);"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** perform the measurement now and execute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "simulation:  COMPLETED {'00': 517, '11':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mLQP/hAIDJE/6boUX3TNEzritXrkCr1WL79u1YuHDhXfvu27cPS5YsQXFxMSZOnAgAePzxx1FaWorVq1fjjTfesFtdtbW1CAwMREVFBUaNGmVu12q12Lp1a6+12sOG9Mx+H4OIyJEY9ElW9VP0AuTi4mI4OTlhwYIFd+23d+9eLF++HAcOHDCHFgBkZ2fjq6++Mr8HZS9qtRoAuk1JtrS0QKPR2HWsO7H2P5BIFPUXGzHC11vpMmgAUHSqsLGxEZ6ennBycrpjn6ysLCxfvhx5eXmIioqyeC4gIKBf6vLw8EBgYCBOnjxpbquoqIDJZOrTVCURgaFFdqPoGVdYWBgqKyuRl5eHuXPnwmQywWg0IiYmBgCQkZGBLVu2ID8/H+Hh4bLWlpSUhPT0dERFRcHLywt6vR4xMTGyLczgVCER3W+snWlSfFXhrl27kJaWhvr6eqjVaixduhRbt279tTgnJzg7O8PV1dVin7a2NvPj7Oxs1NXV3fU9rrS0NHzyySc4ffq01XV1dnZCr9cjOzvbvNIxMzMT3t78q5GISEmKB9e9sia4iIho4BA6uJYuXQqj0YiOjg48/PDDyMvLU7okIiLqZ0IHFxER3X8UvwCZiIjIFgwuIiISCoOLiIiEwuAiIiKhMLiIiEgoDC4iIhIKg4uIiITC4CIiIqEwuIiISCgMLiIiEgqDi4iIhMLgIiIioTC4iIhIKAwuIiISCoOLiIiEwuAiIiKhMLiIiEgoDC4iIhIKg4uIiITC4CIiIqEwuIiISCgMLiIiEgqDi4iIhMLgIiIioTC4iIhIKAwuIiISCoOLiIiE8v8AS5u8Iwp8nhwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2276c4e1e48>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "circuit.measure(qr, cr)\n",
    "execute_locally(circuit,draw_circuit=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Why is this measurement different from the previous one?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> Since we applied the Hadamard gate on our qubits, their superposition was shifted accordingly, meaning the $\\alpha$ and $\\beta$ on the superposition were rotated by 45º. Once we measure, now, the result should be interpreted in the plus-minus basis, meaning that 1 is |+> and 0 is |->."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Free flow\n",
    "Take a look at the following explanation of Entanglement, taken from the [qiskit-tutorial](https://github.com/Qiskit/qiskit-tutorial/blob/master/community/terra/qis_intro/entanglement_introduction.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Entanglement\n",
    "\n",
    "The core idea behind the second Principle is *entanglement*. Upon reading the Principle, one might be inclined to think that entanglement is simply strong correlation between two entitities -- but entanglement goes well beyond mere perfect (classical) correlation. If you and I read the same paper, we will have learned the same information. If a third person comes along and reads the same paper they <i>also</i> will have learned this information. All three persons in this case are perfectly correlated, and they will remain correlated even if they are separated from each other. \n",
    "\n",
    "The situation with quantum entanglement is a bit more subtle. In the quantum world, you and I could read the same quantum paper, and yet we will not learn what information is actually contained in the paper until we get together and share our information. However, when we are together, we find that we can unlock more information from the paper than we initially thought possible. Thus, quantum entanglement goes much further than perfect correlation.\n",
    "\n",
    "To demonstrate this, we will define the controlled-NOT (CNOT) gate and the composition of two systems. The convention we use Qiskit is to label states by writing the first qubit's name in the rightmost position, thereby allowing us to easily convert from binary to decimal. As a result, we define the tensor product between operators $q_0$ and $q_1$ by $q_1\\otimes q_0$. \n",
    "\n",
    "Taking $q_0$ as the control and $q_1$ as the target, the CNOT with this representation is given by\n",
    "\n",
    "$$ CNOT =\\begin{pmatrix} 1 & 0 & 0 & 0\\\\ 0 & 0 & 0 & 1\\\\0& 0& 1 & 0\\\\0 & 1 & 0 & 0 \\end{pmatrix},$$\n",
    "\n",
    "which is non-standard in the quantum community, but more easily connects to classical computing, where the least significant bit (LSB) is typically on the right. An entangled state of the two qubits can be made via an $H$ gate on the control qubit, followed by the CNOT gate. This generates a particular maximally entangled two-qubit state known as a Bell state, named after John Stewart Bell ([learn more about Bell and his contributions to quantum physics and entanglement](https://en.wikipedia.org/wiki/John_Stewart_Bell)). \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Entanglement on a real device\n",
    "**TASK:** Create a simple entanglement and execute it on a real device."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "qr, cr, circuit = new_circuit(2)\n",
    "circuit.h(qr[0])\n",
    "circuit.cx(qr[0], qr[1])\n",
    "circuit.h(qr)\n",
    "circuit.measure(qr, cr);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running on current least busy device:  ibmq_16_melbourne\n",
      "Status @ 0 seconds\n",
      "JobStatus.INITIALIZING\n",
      "Status @ 10 seconds\n",
      "JobStatus.QUEUED\n",
      "Status @ 20 seconds\n",
      "JobStatus.QUEUED\n",
      "Status @ 30 seconds\n",
      "JobStatus.QUEUED\n",
      "Status @ 40 seconds\n",
      "JobStatus.QUEUED\n",
      "Status @ 50 seconds\n",
      "JobStatus.RUNNING\n",
      "Status @ 60 seconds\n",
      "JobStatus.RUNNING\n",
      "JobStatus.DONE\n",
      "experiment:  COMPLETED {'00': 455, '01': 41, '10': 51, '11': 477}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvAOZPmwAADTpJREFUeJzt3X+o3fV9x/Hna0ltx340aq4iSVyEhlH/qZWLZPjPpu3wx1iy0YBlzCCB/GN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16PLkKGfmXOdnuHZ4EvtDk7gQNTWt/FzttjjN9Bln7nwN89nYWhX4F2Hf7U7R2OAE+02zt8BbgvyTxwJbBvequ8eJ3t+CX5rSQLLJ3hv5rkq9Nc58UqydeAvwd+PslCkl3A/cDnkxwFPt/2NcCg45fk19rv3i8ATyX51nRXORl+MlaSOucZvSR1ztBLUucMvSR1ztBLUucMvSR1ztBLUucMvSR1ztBLUuf+B23dJgNucajQAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2276c5acbe0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "execute_remotely(circuit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**TASK:** Comment on the results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> \n",
    "**Important:** Once you get the results, you may see that, in fact, most of the iterations resulted in `00` and `11`. The remaining options `01` and `10` are due to the immense difficulty with which quantum entanglement is preserved in nowadays labs' conditions. Nonetheless, these are still extraordinary results!"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
